//
//  HDMediator.h
//  HDMediator
//
//  Created by apple on 2017/4/25.
//  Copyright © 2017年 com.devin.definesys. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef NS_ENUM(NSUInteger,HDMediatorResult) {
    HDMediatorResultOK = 0,
    HDMediatorResultActionNotFound = 10404,
    HDMediatorResultClassNotFound = 10405,
    HDMediatorResultSchemeNotFound = 10410,
    HDMediatorResultHostNotFound = 10411,
    HDMediatorResultFragmentError = 10500,
};

@protocol HDMediatorAllowSecurityDelegate <NSObject>

@optional
//Url跳转权限
-(BOOL) allowUrlRequest ;
-(NSArray<NSString *> *) allowHosts ;
-(NSArray<NSString *> *) allowScheme ;

@end

@protocol HDMediatorTargetActionDelegate <NSObject>

//返回值,@"target",@"action",@"params",参数必须是原始类型的值
-(NSDictionary *) targetActionForTargetNotFound:(NSString *)url ;
-(NSDictionary *) targetActionForTargetError:(NSString *)url ;

@end

@interface HDMediator : NSObject

@property(nonatomic) id securityDelegate ;
@property(nonatomic) id targetActionDelegate ;

+ (instancetype)sharedInstance;

// 远程App调用入口
- (id)performActionWithSchemeUrl:(NSURL *)schemeUrl params:(NSDictionary *)params completion:(void (^)(NSDictionary *))completion ;

// 本地组件调用入口
- (id)performTarget:(NSString *)targetName action:(NSString *)actionName params:(NSDictionary *)params shouldCacheTarget:(BOOL)shouldCacheTarget;

- (void)releaseCachedTargetWithTargetName:(NSString *)targetName;

// 远程方法调用，不建议使用。可能会引起某些异常
- (id)performActionWithUrl:(NSURL *)url completion:(void(^)(NSDictionary *info))completion NS_DEPRECATED_IOS(2_0, 10_0);

@end
